import { createService } from "../request"
const rq = createService('/myapi')

// 获取商品列表
export function getGoodsList(page, params) {
  return rq({
    url: `/admin/goods/${page}`,
    method: 'GET',
    params
  })
}

// 添加商品
export function createGoods(data) {
  return rq({
    url: '/admin/goods',
    method: 'POST',
    data,
    headers: {
      'Content-Type': 'application/json'
    }
  })
}

// 修改商品
export function updateGoods(data) {
  return rq({
    url: `/admin/goods/${data.id}`,
    method: 'POST', 
    data,
    headers: {
      'Content-Type': 'application/json'
    }
  })
}

// 批量修改状态
export function updateGoodsStatus(ids, status) {
  return rq({
    url: '/admin/goods/changestatus',
    method: 'POST',
    data: {
      ids,
      status
    },
    headers: {
      'Content-Type': 'application/json'
    }
  })
}

// 修改商品
export function deleteeGoodsById(id) {
  let ids = []
  ids.push(id)
  return deleteGoods(ids)
}

// 批量删除
export function deleteGoods(ids) {
  return rq({
    url: '/admin/goods/delete_all',
    method: 'POST',
    data: {
      ids
    },
    headers: {
      'Content-Type': 'application/json'
    }
  })
}


// 批量删除
export function addBannersById(id, banners) {
  return rq({
    url: `/admin/banners/goods/${id}`,
    method: 'POST',
    data: {
      banners
    },
    headers: {
      'Content-Type': 'application/json'
    }
  })
}